﻿using Abp.vNext.WT.WebApi.Issues.MyProject.Issues;
using Abp.vNext.WT.WebApi.Issues;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Abp.vNext.WT.WebApi.WebApiTestDataSeedContributor;
using Volo.Abp;
using Xunit;
using Shouldly;
using Volo.Abp.Testing;

namespace Abp.vNext.WT.WebApi.Issue_Tests
{
    /// <summary>
    /// 集成测试-测试领域服务
    /// WebApiDomainTestBase主要继承自 AbpIntegratedTest<T> 类
    /// </summary>
    public class IssueManager_Integration_Tests : WebApiDomainTestBase
    {
        

        private readonly IssueManager _issueManager;
        private readonly Issue _issue;

        public IssueManager_Integration_Tests()
        {
            _issueManager = GetRequiredService<IssueManager>();
            _issue = new Issue
            {
                Title = "Test title",
                Description = "Test description"
            };
        }

        [Fact]
        public async Task Should_Not_Allow_To_Assign_Issues_Over_The_Limit()
        {
            // Act & Assert
            await Assert.ThrowsAsync<BusinessException>(async () =>
            {
                await _issueManager.AssignToUserAsync(_issue, TestData.User1Id);
            });

            _issue.AssignedUserId.ShouldBeNull();
        }

        [Fact]
        public async Task Should_Assign_An_Issue_To_A_User()
        {
            // Act
            await _issueManager.AssignToUserAsync(_issue, TestData.User2Id);

            //Assert
            _issue.AssignedUserId.ShouldBe(TestData.User2Id);
        }
    }
}
